package com.taiyuan.zfmvp.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

/**
 * @param request
 * @Author: zhoufang@si-tech.com.cn
 * @Descriiption: base64加解密使用
 * @Date 2022/2/12
 * @return
 */
public class Base64Util {

    /***
     * BASE64解密
     * @param key
     * @return
     * @throws Exception
     */
    public static byte[] decryBASE64(String key) throws Exception{
        return (new BASE64Decoder()).decodeBuffer(key);
    }

    /***
     * BASE64加密
     * @param key
     * @return
     * @throws Exception
     */
    public static String encryptBASE64(byte[] key) throws Exception{
        return (new BASE64Encoder()).encode(key);
    }

    public static void main(String[] args) {
        try {
            String mima = "zhoufang1234";
            String str = encryptBASE64(mima.getBytes());
            System.out.println(str);//emhvdWZhbmcxMjM0

            byte[] bytestrr = decryBASE64("emhvdWZhbmcxMjM0");
            System.out.println(new String(bytestrr));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
